
package com.su.dev.current;

import java.util.List;

import com.dev.su.bean.Bean;
import com.dev.su.db.DbConnector;
import com.dev.su.filter.URLMatcher;
import com.dev.su.util.Md5Util;

public class DownloadTask extends BaseTask<String> {
    private String mDownUrl;

    public DownloadTask(String urlString) {
        mDownUrl = urlString;
    }

    @Override
    protected String doInBackground(String in) {
        String html = URLMatcher.getHtml(in);
        List<String> imageUrls = URLMatcher.getImageUrl(html);
        for (String string : imageUrls) {
            Bean bean = new Bean();
            String realImgSrc = URLMatcher.getRealImgSrc(string);
            bean.setmDesUrl(realImgSrc);
            bean.setmMd5(Md5Util.getStringMd5(realImgSrc));
            bean.setmSrcUrl(in);
            DbConnector connector = new DbConnector();
            connector.insertImgBean(bean);
        }

        return null;
    }

    /**
     * 这个应该回到主线程的
     */
    @Override
    protected String prepExcute() {
        return mDownUrl;
    }

    @Override
    protected void postExcute(String result) {
    }

}
